#set( $symbol_pound = '#' )
#set( $symbol_dollar = '$' )
#set( $symbol_escape = '\' )
package ${package}.common.convert;

import com.alibaba.fastjson.serializer.ValueFilter;
import lombok.extern.slf4j.Slf4j;

/**
 * Description: 整型转字符串
 *
 * @author wupanhua
 * @date 2019/8/6 15:28
 *
 * <pre>
 *              ${copyright}
 *      Copyright (c) 2019. All Rights Reserved.
 * </pre>
 */
@Slf4j
public class LongStringFilter implements ValueFilter {

    /**
     * Description:
     * <实现接口方法>
     * @author wupanhua
     * @date 14:35 2019/8/8
     * @param object 1
     * @param propertyName 2
     * @param propertyValue 3
     * @return java.lang.Object
     **/
    @Override
    public Object process(Object object, String propertyName, Object propertyValue) {

        if (propertyValue instanceof Long) {
            return String.valueOf(propertyValue);
        }
        // 当字段名称后缀带id时进行数据转换
        String fieldSuffix = "id";
        if (propertyValue instanceof String && propertyName.endsWith(fieldSuffix)) {
            try {
                return Long.valueOf(propertyValue.toString());
            } catch (Exception e) {
                log.error("转换错误：{}, {}", propertyName, propertyValue);
            }
        }

        return propertyValue;
    }
}
